package com.example.xm.presenter.own;

import android.annotation.SuppressLint;

import com.example.xm.base.BasePresenter;
import com.example.xm.bean.OwnBean.UserBean;
import com.example.xm.bean.OwnBean.UserUpdateBean;
import com.example.xm.common.CommonSubScriBer;
import com.example.xm.interfaces.login.ILogin;
import com.example.xm.interfaces.own.IOwn;
import com.example.xm.model.HttpManager;
import com.example.xm.utiles.RxUtils;

import java.util.Map;

public class LoginPresenter extends BasePresenter<IOwn.LoginView> implements IOwn.LoginPersenter {
    @Override
    public void login(Map<String, String> map) {
        addSubscribe(
                HttpManager
                        .getInstance()
                        .getUserApi()
                        .login(map)
                        .compose(RxUtils.rxScheduler())
                        .subscribeWith(new CommonSubScriBer<UserBean>(mView) {
                            @Override
                            public void onNext(UserBean bean) {
                                mView.loginReturn(bean);
                            }
                        }));
    }

    @SuppressLint("CheckResult")
    @Override
    public void register(Map<String, String> map) {
        HttpManager
                .getInstance()
                .getUserApi()
                .register(map)
                .compose(RxUtils.rxScheduler())
                .subscribeWith(new CommonSubScriBer<UserBean>(mView) {
                    @Override
                    public void onNext(UserBean bean) {
                        mView.registerReturn(bean);
                    }
                });
    }
}
